<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>3-事件处理器</title>
		
		<script type="text/javascript" src="../../lib/vue/vue.min.js" ></script>
		<!--<link  id="style_sheet" rel="stylesheet" href="../../css/css01.css" />-->
		<style type="text/css">
			@charset "utf-8";
			*{ padding: 0px;margin: 0px; }
			
			/* body的全局样式  */
			body{font-family:"微软雅黑";font-weight: normal;}
			
			/* dbody 居中 */
			.dbody{
				margin-left:auto;
				margin-right: auto;
				width: 1500px;
				height: 6000px;
				border: #CCCCCC 1px solid;
				box-shadow: #CCCCCC 5px 5px 5px 5px;
				padding: 10px;
			}
			
			pre{
			    margin: 15px auto;
			    font: 12px 20px Menlo,Monaco,Consolas,"Andale Mono","lucida console","Courier New",monospace;
			    border: 1px solid #ddd;
			    border-left-width: 4px;
			    background: #fbfbfb url(../img/codecolorer_bg.gif) top;
			    padding: 10px 15px;
			}
		</style>
	</head>
	<body class="dbody">
		<h1>1- v-on:xxx指令</h1>
		<div id="app">
			<button v-on:click="counter += 1">点击了{{counter}}次</button>
		</div>
		<script>
			new Vue({
				el:"#app",
				data:{
					counter:0
				}
			})
		</script>
		
		
		<h1>2- 事件修饰符</h1>
		<xmp>
		<!-- 阻止单击事件冒泡 -->
		<a v-on:click.stop="doThis"></a>
		<!-- 提交事件不再重载页面 -->
		<form v-on:submit.prevent="onSubmit"></form>
		<!-- 修饰符可以串联  -->
		<a v-on:click.stop.prevent="doThat"></a>
		<!-- 只有修饰符 -->
		<form v-on:submit.prevent></form>
		<!-- 添加事件侦听器时使用事件捕获模式 -->
		<div v-on:click.capture="doThis">...</div>
		<!-- 只当事件在该元素本身（而不是子元素）触发时触发回调 -->
		<div v-on:click.self="doThat">...</div>
		
		<!-- click 事件只能点击一次，2.1.4版本新增 -->
		<a v-on:click.once="doThis"></a>
		
		<!-- 只有在 keyCode 是 13 时调用 vm.submit() -->
		<input v-on:keyup.13="submit">

		<!-- 同上 -->
		<input v-on:keyup.enter="submit">
			
		<!-- 缩写语法 -->
		<input @keyup.enter="submit">
		
		.enter
		.tab
		.delete (捕获 "删除" 和 "退格" 键)
		.esc
		.space
		.up
		.down
		.left
		.right
		.ctrl
		.alt
		.shift
		.meta
		<p><!-- Alt + C -->
		<input @keyup.alt.67="clear">
		<!-- Ctrl + Click -->
		<div @click.ctrl="doSomething">Do something</div>

		</xmp>
		<div id="app2">
		<button v-on:click.once="doThis">测试只能点击一次</button><br />
		</div>
		<script>
			new Vue({
				el:"#app2",
				data:{},
				methods:{
					doThis:function(){
						alert("Hello world!!!");
					}
				}
			})
		</script>
		
		
		<h1>3- form表单元素</h1>
		<h2>input</h2>
		<div id="app3">
			<input type="text" v-model="inputText" placeholder="请输入..." />
			<input type="text" v-model="inputText" readonly="true" />
		</div>
		<script>
			new Vue({
				el:"#app3",
				data:{
					inputText:""
				}
			})
		</script>
		
		<h2>checkbox</h2>
		<div id="app4">
			<fieldset>
				<legend>单选</legend>
				<input type="checkbox" v-model="checkSingle" @click="changeAllChecked()"/>{{checkSingle}}
			</fieldset>
			<fieldset>
				<legend>多选</legend>
				<!-- <input type="checkbox" id="runoob" value="Runoob" v-model="checkedNames">
				<label for="runoob">Runoob</label>
				<input type="checkbox" id="google" value="Google" v-model="checkedNames">
				<label for="google">Google</label>
				<input type="checkbox" id="taobao" value="Taobao" v-model="checkedNames">
				<label for="taobao">taobao</label> -->
				<template v-for="c in checkedArr">
					<input type="checkbox" :id=c :value=c v-model="checkedNames">
					<label :for=c>{{c}}</label>
				</template>
				你选择的是:{{checkedNames}}
			</fieldset>
		</div>
		<script>
			new Vue({
				el:"#app4",
				data:{
					checkSingle:false,
					checkedNames:[],
					checkedArr:["Runoob", "Google", "Taobao"]
				},
				methods: {
					changeAllChecked: function() {
						if (!this.checkSingle) {
							this.checkedNames = this.checkedArr
						} else {
							this.checkedNames = []
						}
					}
				},
				// watch: {
				// 	"checked": function() {
				// 		if (this.checked) {
				// 			this.checkedNames = this.checkedArr
				// 		} else {
				// 			this.checkedNames = []
				// 		}
				// 	}
				// }
			})
		</script>
		<h3>radio</h3>
		<div id="app5">
		  <input type="radio" id="runoob" value="Runoob" v-model="picked">
		  <label for="runoob">Runoob</label>
		  <br>
		  <input type="radio" id="google" value="Google" v-model="picked">
		  <label for="google">Google</label>
		  <br>
		  <span>选中值为: {{ picked }}</span>
		</div>

		<script>
			new Vue({
			  el: '#app5',
			  data: {
				picked : 'Runoob'
			  }
			})
		</script>
		
		<h2>select</h2>
		<div id="app6">
			<select v-model="selected">
				<option value="">--请选择--</option>
				<option value="Google">Google</option>
				<option value="BaiDu">BaiDu</option>
				<option value="YaHoo">YaHoo</option>
			</select>
			你选择的是：{{selected}}
		</div>
		<script>
			new Vue({
				el:"#app6",
				data:{
					selected:"Google"
				}
			})
		</script>
		
		
		<h1>4- 修饰符</h1>
		<h2>.lazy</h2>
		<p>在默认情况下， v-model 在 input 事件中同步输入框的值与数据，但你可以添加一个修饰符 lazy ，从而转变为在 change 事件中同步：</p>
		<xmp>
		<!-- 在 "change" 而不是 "input" 事件中更新 -->
		<input v-model.lazy="msg" >
		</xmp>
		
		<h3>.number</h3>
		<p>如果想自动将用户的输入值转为 Number 类型（如果原值的转换结果为 NaN 则返回原值），可以添加一个修饰符 number 给 v-model 来处理输入值：</p>
		<xmp>
		<input v-model.number="age" type="number">
		</xmp>
		
		<h3>.trim</h3>
		<p>如果要自动过滤用户输入的首尾空格，可以添加 trim 修饰符到 v-model 上过滤输入：&lt;input v-model.trim="msg"&gt;</p>
		
		<div id="app7">
			<lable>v-model.lazy</lable>
			<input type="text" v-model.lazy="msg" /><input type="text" v-model="msg" readonly="true"/><br />
			
			<lable>v-model.number</lable>
			<input type="number" v-model.number="age" /><input type="number" v-model.number="age" readonly="true"/><br />
			
			<lable>v-model.trim</lable>
			<input type="text" v-model.trim="msg2" /><input type="text" v-model.trim="msg2" readonly="true"/><br /><br />
		</div>
		<script>
			new Vue({
				el:"#app7",
				data:{
					msg:"",
					age:0,
					msg2:""
				}
			})
		</script>
		
	</body>
</html>
